#ifndef __SWEI_FW_INFO_H
#define __SWEI_FW_INFO_H

#include <time.h>
#include <stdint.h>
#include "service/include/swei_common.h"

#ifdef __cplusplus
extern "C" {
#endif


/* get device info enum */
typedef enum
{
    /* IMEI_INFO_BCD 仅用于获取IMEI转换之后的BCD码,不要做任何设置,原始IMEI到BCD码的转换是内部的事情 */
    IMEI_INFO_BCD      = 0x00,
    ICCID_INFO         = 0x02,
    SW_VERSION_INFO    = 0x03,
    HW_VERSION_INFO    = 0x04,
    SN_INFO            = 0x05,
    /* 原始IMEI信息,长度为16 */
    IMEI_INFO          = 0x06,
    LIBAT_INFO,         /*!< 锂电池小电池信息 */
    LIBAT_CHARGER_INFO,
    SINAL_QUALITY,
    BATT_INFO,
    CHG_STAT,
    ECON_INFO,
    ECON_STAT,
    ECON_BASIC_INFO,
    BIKE_DATA1,
    BIKE_DATA2,
    BIKE_STAT,
    FAULT_CODE,
}device_info_e;

/**
 * @brief 锂电池(小电池)数据结构
 */
typedef struct {
    float temp;
	float volt;
	float power;   /*percentage of total power*/	
}libat_info_t;

/**
 * @brief 锂电池(小电池)充电状态数据结构
 */
typedef struct
{
    int16_t charge_count;       // 充电次数
    int32_t charge_total_time;  // 充电总时间 s
}libat_charger_info_t;

typedef __packed struct
{
    uint8_t  tbox_model;
    uint8_t  tbox_iccid[32];
    uint8_t  tbox_imei[8];
    uint8_t  tbox_ble_mac[6];   //蓝牙地址
}tbox_info_t;

typedef enum
{
    tbox_version_type = 0,
    tbox_version_type_lib,
    tbox_version_type_sdk,
    tbox_version_type_ble,
    tbox_version_type_mcu,
    tbox_version_type_num,
}tbox_version_type_t;

typedef __packed struct
{
    uint8_t  version_type;
    char     version[32];
}tbox_version_t;

typedef __packed struct
{
    uint8_t  csq;
    uint8_t  rsrp;
}signal_quality_t;

typedef __packed struct
{
    uint16_t volt;
    uint8_t volt_percent;  
}batt_info_t;

typedef __packed struct
{   
    uint16_t speed;         /* 车速 : 0.01Km/h	*/
    uint16_t temp;          /* 电机温度 : 0.1摄氏度 */
    uint16_t torque_volt;   /* 力矩电压值 */
    uint16_t motor_speed;   /* 电机转速 */
    uint16_t ride_freq;      /* 踏频 */
    uint16_t bus_volt;      /* 母线电压 : 0.1V */
    uint16_t bus_cur;       /* 母线电流 : 0.1A */
    uint16_t braking_stat;  /* 断电刹状态 */
    uint8_t  throttle_volt;  /* 转把电压 : 0.1V */
}econ_info_t;

typedef __packed struct
{   
    uint8_t pwr_lvl;
    uint8_t econ_work_stat;
    uint8_t econ_mode;
    uint8_t vehicle_stat;
}econ_stat_t;

typedef __packed struct
{   
    uint8_t sn_len;
    char sn[32];
    uint8_t hw_ver_len;
    char hw_ver[32];
    uint8_t soft_ver_len;
    char soft_ver[32];
    uint8_t eeprom_len;
    char eeprom[6];
    uint16_t wheel_diameter;    /* 轮圈直径，单位：0.1in	 */
}econ_basic_info_t;

typedef __packed struct
{   
    uint16_t remain_range;    /* 续航里程 (0.01km/h)*/
    uint8_t remain_volume;      /* 剩余电量 (%)*/
}bike_data1_t;

typedef __packed struct
{   
    uint16_t single_range;      /* 单次里程 : 0.01km/h */
    uint32_t total_range;       /* 总里程 : 0.01km/h */
}bike_data2_t;

typedef __packed struct
{
    uint8_t ride_stat;
    uint8_t elock_stat;
    uint8_t charger_stat;           /* 充电器连接状态 */
    uint8_t tailight_stat;         /* 尾灯状态 */ 
}bike_stat_t;

/**
 * @brief 获取设备信息
 * 
 * @param type 
 * @param p_get_info 
 * @param get_info_size 
 * @return int32_t 
 */
int32_t swei_get_device_info(device_info_e type, void *p_get_info, uint32_t get_info_size);

/**
 * @brief 判断配置是否就绪
 * 
 * @return true 
 * @return false 
 */
bool swei_config_ready(void);

#ifdef __cplusplus
}
#endif

#endif  // __SWEI_FW_INFO_H